package com.supermap.dataservice.cloud.productC.specialty;

import com.alibaba.dubbo.config.annotation.Service;
import com.supermap.dataservice.mysql.config.DynamicDataSourceContextHolder;
import com.supermap.dataservice.util.JSONUtils;
import com.supermap.dubbo.api.cloud.productC.SpecialtyService;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author aqua
 * @desc
 * @date 2019年04月11 11:10
 * @email 1301584033@qq.com
 */
@Service
public class SpecialtyServiceImpl implements SpecialtyService {


    @Resource
    private SpecialtyMapper specialtyMapper;
    @Override
    public JSONUtils getProductSpecialtyList(Integer farmId, Integer pageSize) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        return new JSONUtils().setData(specialtyMapper.getProductSpecialtyList(farmId,pageSize));
    }

    @Override
    public JSONUtils getProductSpecialtyGrop(Integer userId, String keyName) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        return new JSONUtils().setData(specialtyMapper.getSpecialtyGrop(userId,keyName));
    }


    @Override
    public JSONUtils getSpecialtyByUserIdList(String userId, Integer pageNum, Integer pageSize,Integer groupId) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        return new JSONUtils().setData(specialtyMapper.getSpecialtyByUserIdList(userId,(pageNum-1)*pageSize,pageSize,groupId)).setCountSum(specialtyMapper.getSpecialtyByUserIdListCountSum(userId,groupId));
    }

    @Override
    public JSONUtils getSpecialtyByUserIdListJsonL(String userId, String areacode, Integer groupId) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        List<Map<String,Object>> list = specialtyMapper.getSpecialtyByUserIdListJsonL(userId,areacode,groupId);
        return new JSONUtils().setData(list).setCountSum(list != null ? list.size():0);
    }

    @Override
    public JSONUtils getSpecialtyCatalogByAreaCode(String areaCode,String sdate,String edate) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        List<Map<String,Object>> list = specialtyMapper.getSpecialtyCatalogByAreaCode(areaCode,sdate,edate);
        return new JSONUtils().setData(list).setCountSum(list != null ? list.size():0);
    }

    @Override
    public JSONUtils getSpecialtyImgListByCodeAndModeName(String areaCode, String modeName) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        List<Map<String,Object>> list = specialtyMapper.getSpecialtyImgListByCodeAndModeName(areaCode,modeName);
        return new JSONUtils().setData(list).setCountSum(list != null ? list.size():0);
    }
}
